'use strict';

const Controller = require('egg').Controller;
const mongoose = require('mongoose');
class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    mongoose.connect('mongodb://127.0.0.1:27017/shop', { useNewUrlParser: true, useUnifiedTopology: true });
    const con = mongoose.connection;
    con.on('error', console.error.bind(console, '连接数据库失败'));
    con.once('open', () => {
      console.log('连接成功');
    });
    ctx.body = 'hi, egg';
  }
  async addUser() {
    this.ctx.body = this.ctx.service.user.add();
  }
  async findUser() {
    this.ctx.body = this.ctx.service.user.find();
  }
  async addUsers() {
    this.ctx.body = this.ctx.service.goods.add();
  }
  async testCore() {
    this.ctx.body = 'ok';
  }
}

module.exports = HomeController;
